package com.wondersgroup.fjzlpt.yyzyzx.controller.rest.yyzygl;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.yyzyzx.util.ControllerUtils;
import com.wondersgroup.fjzlpt.yyzyzx.service.inter.yyzygl.CwyyglService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 床位预约管理
 * <p>
 * <p>
 * Created by sanma on 2017/8/2.
 */
@RestController
@RequestMapping("/cwyygl")
public class CwyyglRestController {
	
	@Autowired
    private CwyyglService cwyyglService;

    /**
     * 分页查询床位信息
     * @param request
     * @return
     */
    @RequestMapping("/queryPage")
    public JSONObject pageQueryAll(HttpServletRequest request){
        Map map = RequestUtils.GetParameterMap(request);
        ControllerUtils.setQueryParams(map,request);
        //JSONObject requestData = com.wondergroup.fjzlpt.tyzyzx.util.RequestUtils.getRequestData(request);
        //if(!requestData.getBoolean("isManager")){
        //    map.put("YLJGDM" , requestData.get("YLJGDM"));
        //}else{
        //    if(StringUtils.isEmpty(map.get("XZQHDM").toString())){
        //        String xzqhdm = QuickPrincipalUtils.getXzqhdm(request);
        //        map.put("XZQHDM" , xzqhdm);
        //    }
        //}
        return cwyyglService.queryPage(map);
    }

    /**
     * 保存/修改  床位预约管理
     * @param request
     * @return
     */
    @RequestMapping("save")
    public JSONObject save(HttpServletRequest request){
        Map map = RequestUtils.GetParameterMap(request);
        return cwyyglService.save(map);
    }
    
    /**
     * 导出数据到Excel文件
     * @param request
     * @param response
     */
    @RequestMapping("/downloadToExcel")
    public void downloadToExcel(HttpServletRequest request, HttpServletResponse response){
    	Map map = RequestUtils.GetParameterMap(request);
        ControllerUtils.setQueryParams(map,request);
    	cwyyglService.downloadToExcel(map, request, response);
    }

    /**
     * 通过PTJGID查询一级科室信息
     * @param request
     * @return
     */
    @RequestMapping("queryYjksByPtjgid")
    public JSONArray queryKsxxByPtjgid(HttpServletRequest request){
        Map map = RequestUtils.GetParameterMap(request);
        return cwyyglService.queryYjksByPtjgid(map);
    }

    /**
     * 通过PTJGID查询病区信息列表
     * @param request
     * @return
     */
    @RequestMapping("queryBqxxByPtjgid")
    public JSONArray queryBqxx(HttpServletRequest request){
        Map map = RequestUtils.GetParameterMap(request);
        return cwyyglService.queryBqxxByPtjgid(map);
    }

    /**
     * 下载床位预约管理Excel模板
     * @param response
     * @return
     */
    @RequestMapping("downExcelModel")
    public void downExcelModel(HttpServletRequest request, HttpServletResponse response){
        cwyyglService.downExcelModel(request, response);
    }

    /**
     * 下载床位预约管理模板值域
     * @param response
     * @return
     */
    @RequestMapping("downExcelModelZy")
    public void downExcelModelZy(HttpServletRequest request, HttpServletResponse response){
        cwyyglService.downExcelModelZy(request, response);
    }

    /**
     * 解析上传的Excel数据
     * @param request
     * @return
     */
    @RequestMapping("parseExcalData")
    public String parseExcalData(@RequestParam(value="fileField", required = false) MultipartFile file, HttpServletRequest request){
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//        Map<String, MultipartFile> files = multipartRequest.getFileMap();
        return cwyyglService.parseExcalData(file, request);
    }

    /**
     * 保存Excel数据
     * @param request
     * @return
     */
    @RequestMapping("saveBatch")
    public JSONObject saveBatch(HttpServletRequest request){
        Map map = RequestUtils.GetParameterMap(request);
        return cwyyglService.saveBatch(map);
    }

    /**
     * 查询一级科室和病区（导入页面）
     * @param request
     * @return
     */
    @RequestMapping("queryKsAndBq")
    public JSONObject queryKsAndBq(HttpServletRequest request){
        Map map = new HashMap();
        map.put("PTJGID", QuickPrincipalUtils.getPtjgID(request));
        return cwyyglService.queryKsAndBq(map);
    }


}
